﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace INSTA.BankApplication.Engine
{
    /// <summary>
    /// The Bank.
    /// </summary>
    public class Bank
    {
        private List<AccountBase> _accounts;


        #region -- Singleton Design Pattern Implementation --

        private static Bank _instance;

        /// <summary>
        /// Private constructor to prevent instanciation 
        /// from outside the class.
        /// </summary>
        private Bank()
        {
            _accounts = new List<AccountBase>();
        
        }

        /// <summary>
        /// Returns the <see cref="Bank"/>'s unique instance.
        /// </summary>
        /// <returns></returns>
        public static Bank Instance()
        {
            if (_instance == null)
            {
                _instance = new Bank();
            }
            return _instance;
        }

        #endregion


        /// <summary>
        /// Gets or sets the list of accounts.
        /// </summary>
        /// <value>The list of accounts.</value>
        public List<AccountBase> Accounts
        {
            get { return _accounts;     }            
        }

        /// <summary>
        /// Creates the account and stores it in the bank's accounts list.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="initialDeposit">The initial deposit.</param>
        /// <returns>the newly created account..</returns>
        public AccountBase CreateAccount(Customer customer, double initialDeposit)
        {
            AccountBase result = AccountFactory.Create(customer, initialDeposit);

            _accounts.Add(result);

            return result;
        }


    }
}
